package com.ling.pl.core.commons.support;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * bo.wang 分页对象
 */
public class DaoPage {

    /**
     * 记录总数
     **/
    private int recordCount;
    private int total;
    private int size;

    /**
     * 当前页页数
     **/
    private int pageIndex;
    private int number;
    private int startPage;
    private int page;

    /**
     * 每页记录数
     **/
    private int pageSize;
    private int totalPages;

    /**
     * 当前页数据集
     **/
    private Collection<?> result = new ArrayList<Object>();
//    private Collection<?> rows = new ArrayList<Object>();
//    private Collection<?> content = new ArrayList<Object>();

    /**
     * 构造函数
     *
     * @param recordCount 总记录数
     * @param pageIndex   当前页数
     * @param pageSize    每页记录数
     * @param result      当前页数据集
     */
    public DaoPage(int recordCount, int pageIndex, int pageSize, List<?> result) {
        super();
        this.recordCount = recordCount;
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.result = result;
    }

    public DaoPage() {
        super();
    }

    /**
     * 获取总页数
     *
     * @return
     */
    public int getPageCount() {
        if (pageSize == 0) return 0;
        if (recordCount % pageSize == 0)
            return recordCount / pageSize;
        else
            return recordCount / pageSize + 1;
    }

    /**
     * 获取当前页数
     *
     * @return
     */
    public int getPageIndex() {
        return pageIndex;
    }

    /**
     * 设置当前页数
     *
     * @param pageIndex
     * @author dada
     */
    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

//    public Collection<?> getRows() {
//        return result;
//    }

    /**
     * 获取每页记录数
     *
     * @return
     */
    public int getPageSize() {
        return pageSize;
    }

    /**
     * 设置每页记录数
     *
     * @param pageSize
     * @author dada
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * 获取总记录数
     *
     * @return
     */
    public int getRecordCount() {
        return recordCount;
    }

    /**
     * 设置总记录数
     *
     * @param recordCount
     * @author dada
     */
    public void setRecordCount(int recordCount) {
        this.recordCount = recordCount;
    }

    public int getTotal() {
        return recordCount;
    }

    /**
     * 当前页首条在数据库里的位置
     *
     * @return
     */
    public int getRecordIndex() {
        return (pageIndex - 1) * pageSize;
    }

    /**
     * 获取分页结果集
     *
     * @return
     */
    public Collection<?> getResult() {
        return result;
    }

    /**
     * 设置记录集
     *
     * @param result
     * @author dada
     */
    public void setResult(Collection<?> result) {
        this.result = result;
    }

    public int getStartPage() {
        return pageIndex;
    }

    public int getTotalPages() {
        return pageSize;
    }

    public int getSize() {
        return recordCount;
    }

    public int getNumber() {
        return recordCount;
    }

    public int getPage() {
        return pageIndex;
    }

//    public Collection<?> getContent() {
//        return result;
//    }
}
